package com.wang.springbootinit.controller;

import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.entity.Makeup;
import com.wang.springbootinit.service.MakeupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 补考审核管理控制器
 */
@RestController
@RequestMapping("/student/makeup")
public class MakeupController {
    @Autowired
    private MakeupService makeupService;


    /**
     * 提交补考审核申请
     * @param makeup 补考审核信息
     * @return 提交结果
     */
    @PostMapping("/submit")
    public BaseResponse submitMakeup(@RequestBody Makeup makeup,HttpServletRequest request) {
        return ResultUtils.success(makeupService.submitMakeup(makeup,request));
    }

    /**
     * 取消补考审核申请
     * @param makeupId 补考审核ID
     * @return 取消结果
     */
    @PostMapping("/cancel/{id}")
    public BaseResponse cancelMakeup(@PathVariable("id") Long makeupId) {
        return ResultUtils.success(makeupService.cancelMakeup(makeupId));
    }

    /**
     * 获取学生的所有补考审核记录
     * @param studentId 学生ID
     * @return 补考审核记录列表
     */
    @GetMapping("/my")
    public BaseResponse getMyMakeups(@RequestParam Long studentId) {
        return ResultUtils.success(makeupService.getMyMakeups(studentId));
    }

    @GetMapping("/list")
    public BaseResponse getCurrentList(HttpServletRequest request) {
        return ResultUtils.success(makeupService.getCurrentList(request));
    }

    /**
     * 根据ID获取补考审核详情
     * @param makeupId 补考审核ID
     * @return 补考审核详情
     */
    @GetMapping("/get/{id}")
    public BaseResponse getMakeupById(@PathVariable("id") Long makeupId) {
        return ResultUtils.success(makeupService.getMakeupById(makeupId));
    }

    /**
     * 分页获取补考申请列表
     * @param current 当前页码
     * @param pageSize 每页数量
     * @param studentId 学生ID（可选）
     * @param status 审核状态（可选）
     * @return 分页结果
     */
    @GetMapping("/list/page")
    public BaseResponse listMakeupByPage(
            @RequestParam(defaultValue = "1") long current,
            @RequestParam(defaultValue = "10") long pageSize,
            @RequestParam(required = false) Long studentId,
            @RequestParam(required = false) Integer status) {
        return ResultUtils.success(makeupService.listMakeupByPage(current, pageSize, studentId, status));
    }
} 